﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Upload</title>
</head>
<body style="height: 100%;">
    <div id="uploader" style="height: 100%; padding: 0px;">
        <div style="padding: 10px; font-size: 15px;">
            <p>
                Your browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.
            </p>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            $("#uploader").plupload({
                // General settings
                runtimes: 'flash,html5,browserplus,silverlight,gears,html4',
                //url: 'UploadFileHandler.ashx',
                url: 'Servlet.ashx?action=UploadFile',
                max_file_size: '1024mb',
                max_file_count: 50, // user can add no more then 50 files at a time
                chunk_size: '1mb',
                rename: true,
                multiple_queues: true,
                // Rename files by clicking on their titles
                rename: true,
                // Sort files
                sortable: false,
                // Specify what files to browse for
                filters: [{
                    title: "Event log files",
                    extensions: "xml"
                }],
                // Flash settings
                flash_swf_url: 'Components/plupload-1.5.7/js/plupload.flash.swf',
                // Silverlight settings
                silverlight_xap_url: 'Components/plupload-1.5.7/js/plupload.silverlight.xap'
            });

            // Client side form validation
            $('form').submit(function (e) {
                var uploader = $('#uploader').plupload('getUploader');
                // Files in queue upload them first
                if (uploader.files.length > 0) {
                    // When all files are uploaded submit form
                    uploader.bind('StateChanged', function () {
                        if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                            $('form')[0].submit();
                        }
                    });
                    uploader.start();
                } else
                    alert('You must at least upload one file.');
                return false;
            });

            // Bind events
            var uploader = $('#uploader').plupload('getUploader');
            uploader.bind('FileUploaded', function (up, file, response) {
                if (response.response == 'Success')
                    showMsg('File uploaded', 'File ' + file.name + ' has been uploaded and parsed successfully, it will be saved immediately.');
                else
                    showMsg('Upload file error', 'Upload file ' + file.name + ' failed. It may be not an valid event log file.');
            });
        });
    </script>
</body>
</html>